package com.github.tangyi.exam.controller.course;

import java.util.List;
import java.util.Map;
import com.github.pagehelper.PageInfo;
import javax.servlet.http.HttpServletResponse;

import com.github.tangyi.api.exam.dto.CourseCertDto;
import com.github.tangyi.api.exam.model.CourseCert;
import com.github.tangyi.common.log.OperationType;
import com.github.tangyi.common.log.SgLog;
import com.github.tangyi.exam.service.course.CourseCertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.tangyi.common.model.R;
import com.github.tangyi.common.utils.SysUtil;
import com.github.tangyi.common.base.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;


@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "课程完结证书管理")
@RequestMapping("/v1/cert")
public class CourseCertController extends BaseController {

    private final CourseCertService courseCertService;

    @GetMapping("/list")
	@Operation(summary = "查询课程完结证书列表")
    public R<PageInfo<CourseCertDto>> list(CourseCertDto courseCert,
                                           @RequestParam(value = PAGE, required = false, defaultValue = PAGE_DEFAULT) int pageNum,
                                           @RequestParam(value = PAGE_SIZE, required = false, defaultValue = PAGE_SIZE_DEFAULT) int pageSize) {
	    return R.success(courseCertService.list(courseCert, pageNum, pageSize));
    }



    @GetMapping(value = "/{id}")
	@Operation(summary = "获取课程完结证书详细信息")
    public R<CourseCert> get(@PathVariable("id") Long id) {
        return R.success(courseCertService.get(id));
    }

    @PostMapping
	@Operation(summary = "新增课程完结证书")
	@SgLog(value = "新增课程完结证书", operationType = OperationType.INSERT)
    public R<Boolean> add(@RequestBody @Valid CourseCert courseCert) {
        courseCert.setCommonValue();
        return R.success(courseCertService.insert(courseCert) > 0);
    }

    @PutMapping("{id}")
	@Operation(summary = "修改课程完结证书")
	@SgLog(value = "修改课程完结证书", operationType = OperationType.UPDATE)
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody @Valid CourseCert courseCert) {
        courseCert.setId(id);
        courseCert.setCommonValue(SysUtil.getUser(), courseCert.getTenantCode());
        return R.success(courseCertService.update(courseCert) > 0);
    }

	@DeleteMapping("{id}")
	@Operation(summary = "删除课程完结证书")
	@SgLog(value = "删除课程完结证书", operationType = OperationType.DELETE)
    public R<Boolean> delete(@PathVariable("id") Long id) {
        CourseCert courseCert = courseCertService.get(id);
        courseCert.setCommonValue();
        return R.success(courseCertService.delete(courseCert) > 0);
    }
}
